package vn.com.vega.chacha.v2.fragment;

import vn.com.vega.chacha.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class NewsDetailFragment extends Fragment {
	// private NewsDetail newsDetailAct;
	public String newsUrl;
	private WebView webView;
	private ProgressBar mProgressBarWebLoadingBar;

	public static NewsDetailFragment newInstance() {
		NewsDetailFragment fragment = new NewsDetailFragment();
		return fragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.news_detail_view, null);
		webView = (WebView) view.findViewById(R.id.web_view_news);
		mProgressBarWebLoadingBar = (ProgressBar) view
				.findViewById(R.id.progressbar_loading_webview);

		webView.setWebChromeClient(webChromeClient);
		webView.setWebViewClient(webViewClient);
		webView.getSettings().setBuiltInZoomControls(true);
		return view;
	}

	WebChromeClient webChromeClient = new WebChromeClient() {
		@Override
		public void onProgressChanged(WebView view, int progress) {
			mProgressBarWebLoadingBar.setProgress(progress);
			if (progress >= 100) {
				mProgressBarWebLoadingBar.setVisibility(View.GONE);
			} else {
				mProgressBarWebLoadingBar.setVisibility(View.VISIBLE);
			}
		}
	};
	
	WebViewClient webViewClient = new WebViewClient() {
		@Override
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        view.loadUrl(url);
	        return true;
	    }
	};

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		webView.loadUrl(newsUrl);
	}

}
